﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Newtonsoft.Json;
using RN.ERP.Web.ModelService;
using System.Configuration;

namespace RN.ERP.Web
{
    public class BaseHandler : IHttpHandler, IRequiresSessionState
    {
        protected SessionUserInfo UserInfo
        {
            get
            {
                if (HttpContext.Current.Session[SessionConstant.SESSION_USERINFO] == null)
                {
                    RebuildSessionUserInfo();
                }
                return HttpContext.Current.Session[SessionConstant.SESSION_USERINFO] == null ? null : (SessionUserInfo)HttpContext.Current.Session[SessionConstant.SESSION_USERINFO];
            }
        }

        /// <summary>
        /// 系统编号
        /// </summary>
        public string AppID
        {
            get
            {
                return ConfigurationManager.AppSettings["AppId"];
            }
        }

        /// <summary>
        /// 重构用户Session数据。
        /// </summary>
        private void RebuildSessionUserInfo()
        {
            UtilitiesTool.RebuildSessionUserInfo();
        }

        public virtual bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public virtual void ProcessRequest(HttpContext context)
        {
            throw new NotImplementedException();
        }
    }
}